package com.example.tetris.Tetris;

import ohos.aafwk.ability.Ability;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.utils.Color;

public class TetrisBackgroundCells extends TetrisEvent {
    //背景小方格颜色（）
    protected Color backgroundCellColor = new Color(Color.rgb(172, 194, 196));
    //下落小方格颜色(红色)
    protected Color blockColor = Color.RED;


    public TetrisBackgroundCells(Ability ability, Component component, int[][] drawBlock) {
        super(ability, component, drawBlock);
    }

    public TetrisBackgroundCells(Ability ability, Component component) {
        super(ability, component);
    }

    //绘制小方格，row 和 col都是从0开始
    public void onDraw(Component component, Canvas canvas) {
        //必须调用父类（TetrisBorder）方法才可绘制边框
        super.onDraw(component, canvas);
        //循环绘制每一个小方格
        for (int i = 0; i < rowCount; i++) {
            for (int j = 0; j < colCount; j++) {
                //判断是否有小方格为空，有则绘制
                if (tetrisData.get(i).get(j) == 0) {
                    //绘制小方格组成的背景
                    drawCell(canvas, i, j, backgroundCellColor);
                } else {
                    //绘制下落的红色小方块
                    drawCell(canvas, i, j, blockColor);
                }
            }
        }

    }
}
